package com.zkk.dao.impl;

import com.zkk.dao.DailyRecordDao;
import com.zkk.pojo.DailyRecord;
import com.zkk.utils.DruidUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.xml.crypto.Data;
import java.math.BigDecimal;
import java.sql.Date;
import java.util.List;

public class DailyRecordDaoImpl implements DailyRecordDao {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(DruidUtil.getDataSource());

    @Override
    public int record(DailyRecord dailyRecord) {
        /*long time = dailyRecord.getDate().getTime();*/

        int update = jdbcTemplate.update("insert into dailyRecord values(?,?,now(),?,?)", dailyRecord.getOutPutCard_Id(), dailyRecord.getInPutCard_Id(), dailyRecord.getAction(), dailyRecord.getMoney());
        return update;
    }

    @Override
    public List<DailyRecord> showAll() {
        List<DailyRecord> query = jdbcTemplate.query("select * from dailyRecord", new BeanPropertyRowMapper<>(DailyRecord.class));
        return query;
    }

    @Override
    public List<DailyRecord> showPage(int begin, int pageSize) {
        List<DailyRecord> query = jdbcTemplate.query("select * from dailyRecord limit ?,?", new BeanPropertyRowMapper<>(DailyRecord.class), begin, pageSize);
        return query;
    }

    @Override
    public int recordSum() {
        Integer integer = jdbcTemplate.queryForObject("select count(*) from dailyRecord", Integer.class);
        return integer;
    }
}
